#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTableWidgetItem>
#include "country.h"
#include "db.h"

QT_BEGIN_NAMESPACE
namespace Ui
{
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget* parent = nullptr);
    ~MainWindow();

private slots:
    void on_pushButton_query_clicked();                             //查询按钮被点击

    void on_tableWidget_1_itemClicked(QTableWidgetItem* item);        //表1某一行被点击

    void on_pushButton_addCountry_clicked();                        //新增参赛国家按钮被点击

    void on_pushButton_addAthlete_clicked();                      //新增运动员按钮被点击

    void on_pushButton_addAthlete_update_clicked();               //编辑运动员信息

    void on_tableWidget_2_itemClicked(QTableWidgetItem* item);      //表2某一行被点击

    void on_pushButton_addAthlete_updateCountry_clicked();

    void readCountry();
    void saveCountry();
    void readAthlete();
    void saveAthlete();

    void queryCountry();
    void add_country(Country &country);
    void add_medal(Athlete &athlete);

    int getSprotsNum();
    int getCountryIndex(QString country);
    int getSportIndex(QString country, QString name);

    void on_pushButton_showCountryRank_clicked();



private:
    void initUI();                          //初始化UI
    void readData();                        //读取txt数据

    void initData1(QString country_name = "");     //初始化表1数据

    void initData2(int type = -1,  QString name = "");            //初始化表2数据

private:
    Ui::MainWindow* ui;
    QString m_chiName;                      //国家名称
    QString m_athleteName;                         //运动员姓名
    QVector<Country> vecCountry;
    db *database;

};

#endif // MAINWINDOW_H
